package com.person.jc.web.security;

import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.person.jc.service.security.TsRoleService;
import com.person.jc.service.security.TsRoleVclService;
import com.person.jc.utils.Servlets;

public class TsRoleVclController extends Controller{
	
	public void init(){
		setAttr("menuId", getPara("menuId"));
		render("main.jsp");
	}
	
	public void list(){
		Map<String,Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
		List<Record> list = TsRoleService.me.getList(map);
		setAttr("list", list);
		render("list.jsp");
	}
	
	public void edit() {
		Map<String,Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
		String view = getAttr("view");
		if(map.size() != 0){
			List<Record> list = TsRoleService.me.getList(map);
			if(list.size() != 0){
				setAttr("role", list.get(0));
			}
		}
		setAttr("view", view);
		render("edit.jsp");
	}
	
	public void save(){
		Map<String,Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
		String res = "success";
		try {
			TsRoleVclService.me.saveRoleVcl(map);
		} catch (RuntimeException e) {
			e.printStackTrace();
			res = "error";
		}
		renderText(res);
	}
}
